﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EasyFlow
{
    /// <summary>
    /// VariableControl.xaml 的交互逻辑
    /// </summary>
    public partial class VariableControl : UserControl
    {
        public ObservableCollection<VariableViewModel> CurrentSelectedVariables
        {
            get { return (ObservableCollection<VariableViewModel>)GetValue(CurrentSelectedVariablesProperty); }
            set { SetValue(CurrentSelectedVariablesProperty, value); }
        }
        public static readonly DependencyProperty CurrentSelectedVariablesProperty =
            DependencyProperty.Register("CurrentSelectedVariables", typeof(ObservableCollection<VariableViewModel>), typeof(VariableControl), new PropertyMetadata(null));
        public ICommand SelectedVariableGroupChangedCommand
        {
            get { return (ICommand)GetValue(SelectedVariableGroupChangedCommandProperty); }
            set { SetValue(SelectedVariableGroupChangedCommandProperty, value); }
        }
        public static readonly DependencyProperty SelectedVariableGroupChangedCommandProperty =
            DependencyProperty.Register("SelectedVariableGroupChangedCommand", typeof(ICommand), typeof(VariableControl), new PropertyMetadata(null));

        public ICommand VariableOperateCommand
        {
            get { return (ICommand)GetValue(VariableOperateCommandProperty); }
            set { SetValue(VariableOperateCommandProperty, value); }
        }
        public static readonly DependencyProperty VariableOperateCommandProperty =
            DependencyProperty.Register("VariableOperateCommand", typeof(ICommand), typeof(VariableControl), new PropertyMetadata(null));

        public VariableControl()
        {
            InitializeComponent();
        }

        private void Button_Delete_Click(object sender, RoutedEventArgs e)
        {

        }
        private void Button_Copy_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Edit_Click(object sender, RoutedEventArgs e)
        {
            ((sender as Button).DataContext as VariableViewModel2).IsEdit = !((sender as Button).DataContext as VariableViewModel2).IsEdit;
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectedVariableGroupChangedCommand?.Execute(VariableGroupListBox.SelectedItem);
        }

        private void VariableButton_Click(object sender, RoutedEventArgs e)
        {
            VariableOperateCommand?.Execute((sender as Button).Name);
        }
    }
}
